package com.wbpay.sdk.formatter;

import com.wbpay.sdk.http.Response;

import org.json.JSONObject;

/**
 * 格式转换
 */

public class Formatter<T> {
    public Response<T> format(String content) {
        Response<T> response = new Response<T>();
        try {
            JSONObject jobj = new JSONObject(content);
            if (jobj.has("state")) {
                response.setCode(jobj.getString("state"));
            }
            if (jobj.has("desc")) {
                response.setMsg(jobj.getString("desc"));
            }
        } catch (Exception e) {
            return null;
        }
        return response;
    }
}
